﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

/// <summary>
/// 物体拖拽功能
/// </summary>
public class DragObj: MonoBehaviour
{
    private Vector3 pos;

    public GameObject curObj;
   
    public float moveSpeed = 0.18f;

    void Update()
    {
        if (Input.touchCount > 1)
            return;

        if (Input.touchCount == 1)
        {
            if (Input.touches[0].phase == TouchPhase.Began )
            {
                curObj.GetComponent<Rigidbody>().useGravity = false;
            }
            //Move object
            if (Input.touches[0].phase == TouchPhase.Moved || Input.touches[0].phase == TouchPhase.Stationary)
            {
                Vector2 touchDeltaPosition = Input.touches[0].deltaPosition;
                
                curObj.transform.Translate(touchDeltaPosition.x * moveSpeed * Time.deltaTime, touchDeltaPosition.y * moveSpeed * Time.deltaTime, 0,Space.World);
            }
            if (Input.touches[0].phase == TouchPhase.Ended)
            {

                curObj.GetComponent<Rigidbody>().useGravity = true;
            }
        }
                
        
    }
}
